//============================================================================================
/**
 * @file	dowsing_sublcd.c
 * @brief	金銀ダウジングマシン処理
 * @author	Hiroyuki Nakamura
 * @date	09.02.09
 */
//============================================================================================
#include "common.h"

#include "gflib/touchpanel.h"
#include "system/lib_pack.h"
#include "system/fontproc.h"
#include "system/arc_util.h"
#include "system/snd_tool.h"
#include "field/field.h"
#include "msgdata/msg.naix"
#include "msgdata/msg_fieldmenu.h"

#include "../field_poketch.h"
#include "../ev_check.h"
#include "../script.h"
#include "../sxy.h"

#include "poketch_arc.h"
#include "dowsing_snd_def.h"
#include "dowsing_gra.naix"

// 日本版未修正バグ定義
#define	BTS_5496_FIX	( GS_BTS5496_20090707_FIX )	// ダウジングのレーダー表示不具合


//============================================================================================
//	定数定義
//============================================================================================

#define ARC_SUBLCDMENU_GRA		( ARC_POKETCH_IMG )

#define	DM_SUB_ACTOR_DISTANCE 	( 256 * FX32_ONE )		// Ｙ座標オフセット
#define DM_RES_TYPE_MAX			( 4 )					// リソースタイプ数

#define	DM_RES_ID				( 498 )					// リソースＩＤ
//#define	RES_LOAD_NONE			( 0xffffffff )			// リソースを読み込まない

#define	DM_CLA_SPECTRE_MAX		( 4 )			// スペクトルの数

#define	THERMOGRAPHY_NULL_CHAR	( 0x1001 )		// サーモグラフィの非表示キャラ（パレット入り）
#define	THERMOGRAPHY_CHAR		( 0x6d )		// サーモグラフィキャラ開始位置
#define	THERMOGRAPHY_PX			( 3 )			// サーモグラフィ表示開始Ｘ座標
#define	THERMOGRAPHY_PY			( 5 )			// サーモグラフィ表示開始Ｙ座標
#define	THERMOGRAPHY_SX			( 15 )			// サーモグラフィ表示位置のＸサイズ
#define	THERMOGRAPHY_SY			( 15 )			// サーモグラフィ表示位置のＹサイズ
#define	RADAR_CX				( 7 )			// レーダー中心Ｘ座標
#define	RADAR_CY				( 7 )			// レーダー中心Ｙ座標

#define	SPECTRE_CX		( 84 )							// スペクトル動作中心Ｘ座標
#define	SPECTRE_CY		( 100 )							// スペクトル動作中心Ｙ座標
#define	SPECTRE_R		( 68 )							// スペクトル半径
#define	SPECTRE_CX_FX32	( SPECTRE_CX << FX32_SHIFT )	// スペクトル動作中心Ｘ座標 (fx32型)
#define	SPECTRE_CY_FX32	( SPECTRE_CY << FX32_SHIFT )	// スペクトル動作中心Ｙ座標 (fx32型)
#define	SPECTRE_R_FX32	( SPECTRE_R << FX32_SHIFT )		// スペクトル半径 (fx32型)

//#define	FX16_TO_FX32(a)	( FX32_CONST( FX_FX16_TO_F32(a) ) )		// fx16 => fx32
//#define	FX32_TO_FX16(a)	( FX16_CONST( FX_FX32_TO_F32(a) ) )		// fx32 => fx16

//#define	PAI		( 3.1415926535 )
#define	PAI		( 180 )

// RES ID
enum {
	DM_RES_ID_BUTTON = DM_RES_ID,
	DM_RES_ID_DOWSING,
};

// RES MAN ID
enum {
	DM_RES_MAN_BUTTON = 0,
	DM_RES_MAN_DOWSING,

	DM_RES_MAN_MAX,
};

// OBJ ID
enum {
	DM_CLA_A_BUTTON = 0,
	DM_CLA_B_BUTTON,
	DM_CLA_B_DASH,
	DM_CLA_RET,
	DM_CLA_SPECTRE,

	DM_CLA_MAX = DM_CLA_SPECTRE + DM_CLA_SPECTRE_MAX
};

// MSG ID
enum {
	DM_MSG_CHECK = 0,	//「しらべる」
	DM_MSG_TALK,		//「はなす」
	DM_MSG_FISH,		//「つり」
	DM_MSG_NEXT,		//「つぎへ」
	DM_MSG_RET,			//「もどる」

	DM_MSG_MAX,
};

// スペクトル動作ワーク
typedef struct {
	u32	now;
	u32	pos;
	u32	prm;
}SPECTRE_WORK;

// ダウジングマシン画面ワーク
typedef struct {
	SUBLCD_PARAM	param;

	// フィールドから渡されるもの
	GF_BGL_INI * bgl;
	u16 * sp_trg;
	FIELDSYS_WORK * fsys;
	void * scr_wk;

	TCB_PTR	tcb;	// 本体のポインタ

	// セルアクター
	CLACT_SET_PTR 			claSet;								// セルアクターセット
	CLACT_U_EASYRENDER_DATA	rndDat;								// 簡易レンダーデータ
	CLACT_U_RES_MANAGER_PTR	resMan[DM_RES_TYPE_MAX];			// リソースマネージャ
	CLACT_U_RES_OBJ_PTR 	resObj[DM_RES_MAN_MAX][DM_RES_TYPE_MAX];		// リソースオブジェテーブル
//	CLACT_HEADER			claHed[DM_RES_MAN_MAX];			// セルアクターヘッダー
	CLACT_WORK_PTR			actWork[DM_CLA_MAX];			// セルアクターワークポインタ配列

	STRBUF * str[DM_MSG_MAX];			// 文字列
	GF_BGL_BMPWIN	win[DM_MSG_MAX];	// BMPWIN

	HIDE_ITEM_LIST * list;	// 隠しアイテムリスト
	s16	item_px;			// 最も近いアイテムのＸ座標
	s16	item_py;			// 最も近いアイテムのＹ座標
	BOOL item_flg;			// アイテム有り無しフラグ
	u32	item_pat;			// アイテム配置パターン

	u32	tpx;		// タッチＸ座標
	u32	tpy;		// タッチＹ座標

	SPECTRE_WORK	spc[DM_CLA_SPECTRE_MAX];	// スペクトルワーク
	u16	spc_move_cnt:15;						// スペクトル動作カウンタ
	u16	spc_flg:1;								// スペクトル表示フラグ
	s16	spc_touch_cnt;							// スペクトルタッチカウンタ

//	u32	grad:14;			// 初期角度
//	u32	mrad:14;			// 移動後角度
//	u32	r_flg:1;			// 角度フラグ
//	u32	mv:3;				// 移動方向

	u8	tg_cnt[THERMOGRAPHY_SY][THERMOGRAPHY_SX];	// サーモグラフィ表示カウンタ

	int	action;

	u16	se_cnt;
	s16	pitch;

	BOOL	radar_hit;

}DM_WORK;

#define HEAPID_SUBLCD_MENU	( HEAPID_POKETCH_APP )		// ヒープＩＤ

typedef void (*pSpectreFunc)(SPECTRE_WORK*);

// BMPWIN
//「はなす」
#define	BMPWIN_TALK_FRM		( GF_BGL_FRAME0_S )
#define	BMPWIN_TALK_PX		( 24 )
#define	BMPWIN_TALK_PY		( 20 )
#define	BMPWIN_TALK_SX		( 8 )
#define	BMPWIN_TALK_SY		( 2 )
#define	BMPWIN_TALK_PAL		( 4 )
#define	BMPWIN_TALK_CGX		( 1 )
//「しらべる」
#define	BMPWIN_CHECK_FRM	( GF_BGL_FRAME0_S )
#define	BMPWIN_CHECK_PX		( 24 )
#define	BMPWIN_CHECK_PY		( 20 )
#define	BMPWIN_CHECK_SX		( 8 )
#define	BMPWIN_CHECK_SY		( 2 )
#define	BMPWIN_CHECK_PAL	( 4 )
#define	BMPWIN_CHECK_CGX	( BMPWIN_TALK_CGX + BMPWIN_TALK_SX * BMPWIN_TALK_SY )
//「つり」
#define	BMPWIN_FISH_FRM		( GF_BGL_FRAME0_S )
#define	BMPWIN_FISH_PX		( 24 )
#define	BMPWIN_FISH_PY		( 20 )
#define	BMPWIN_FISH_SX		( 8 )
#define	BMPWIN_FISH_SY		( 2 )
#define	BMPWIN_FISH_PAL		( 4 )
#define	BMPWIN_FISH_CGX		( BMPWIN_CHECK_CGX + BMPWIN_CHECK_SX * BMPWIN_CHECK_SY )
//「つぎへ」
#define	BMPWIN_NEXT_FRM		( GF_BGL_FRAME0_S )
#define	BMPWIN_NEXT_PX		( 24 )
#define	BMPWIN_NEXT_PY		( 20 )
#define	BMPWIN_NEXT_SX		( 8 )
#define	BMPWIN_NEXT_SY		( 2 )
#define	BMPWIN_NEXT_PAL		( 4 )
#define	BMPWIN_NEXT_CGX		( BMPWIN_FISH_CGX + BMPWIN_FISH_SX * BMPWIN_FISH_SY )
//「もどる」
#define	BMPWIN_RET_FRM		( GF_BGL_FRAME0_S )
#define	BMPWIN_RET_PX		( 26 )
#define	BMPWIN_RET_PY		( 2 )
#define	BMPWIN_RET_SX		( 6 )
#define	BMPWIN_RET_SY		( 2 )
#define	BMPWIN_RET_PAL		( 4 )
#define	BMPWIN_RET_CGX		( BMPWIN_NEXT_CGX + BMPWIN_NEXT_SX * BMPWIN_NEXT_SY )

#define	DEF_SE_PITCH	( -15 * 64 )	// サーチＳＥのデフォルトピッチ


//============================================================================================
//	プロトタイプ宣言
//============================================================================================
static void VramInit(void);
static void BgInit( GF_BGL_INI * bgl );
static void BgExit( GF_BGL_INI * bgl );
static void BgGraLoad( DM_WORK * wk, ARCHANDLE * ah );

static void MsgInit( DM_WORK * wk );
static void MsgExit( DM_WORK * wk );

static void BmpInit( DM_WORK * wk );
static void BmpExit( DM_WORK * wk );

static void ObjInit( DM_WORK * wk, ARCHANDLE * ah );
static void ObjExit( DM_WORK * wk );
static void ClaResManInit( DM_WORK * wk );
static void ClaResManExit( DM_WORK * wk );
static void ClaMenuAdd( DM_WORK * wk );
static void ClaMenuDel( DM_WORK * wk );
static void ClaDowsingAdd( DM_WORK * wk, ARCHANDLE * ah );
static void ClaDowsingDel( DM_WORK * wk );

static void HideItemListCreate( DM_WORK * wk );
static void HideItemListExit( DM_WORK * wk );

static void MainTask( TCB_PTR tcb, void * work );

static void SpectreMoveWorkMake( DM_WORK * wk );
static void SpectreMoveMake01( SPECTRE_WORK * wk );
static void SpectreMoveMake02( SPECTRE_WORK * wk );
static void SpectreMoveMake03( SPECTRE_WORK * wk );
static void SpectreMoveMake04( SPECTRE_WORK * wk );
static void SpectreMoveMake05( SPECTRE_WORK * wk );
static void SpectreTouchCount( DM_WORK * wk, s16 p );
static void SpectreAnime( DM_WORK * wk );
static void SpectreMove( DM_WORK * wk );
static void ThermographyCount( DM_WORK * wk, BOOL flg );
static void SearchSePlay( DM_WORK * wk );
static BOOL TouchPosCheck( DM_WORK * wk );
//static void GlobalRadMake( DM_WORK * wk );

static void TalkButton( DM_WORK * wk );
static void DashButton( DM_WORK * wk );
static void RetButton( DM_WORK * wk );
static BOOL EventCheck( DM_WORK * wk );


//============================================================================================
//	グローバル変数
//============================================================================================

static const RECT_HIT_TBL DashButtonHitTbl = {  86, 134, 178, 252 };	// Ｂボタンタッチ範囲
static const RECT_HIT_TBL TalkButtonHitTbl = { 144, 188, 157, 255 };	// Ａボタンタッチ範囲
static const RECT_HIT_TBL RetButtonHitTbl  = {   8,  39, 192, 255 };	// 戻るボタンタッチ範囲

static const u8 ButtonStrTbl[] = {
	DM_MSG_CHECK,		//「しらべる」
	DM_MSG_TALK,		//「はなす」
	DM_MSG_CHECK,		//「しらべる」
	DM_MSG_FISH,		//「つり」
	DM_MSG_NEXT,		//「つぎへ」
};

// レーダーのタッチ範囲
static const RECT_HIT_TBL RadarHitTbl[] =
{
	{ TP_USE_CIRCLE, 84, 100, 72 },
	{ TP_HIT_END, 0, 0, 0 },
};

// スペクトル動作ワーク作成関数テーブル
static const pSpectreFunc SpectreMoveMake[] = {
	SpectreMoveMake01,
	SpectreMoveMake02,
	SpectreMoveMake03,
	SpectreMoveMake04,
	SpectreMoveMake05,
};

// タッチ中に上昇するカウンタの最大値
static const u8 TouchCountMax[][2] =
{	// スペクトル、サーモグラフィ
	{  50-1,  30-1 },
	{  80-1,  40-1 },
	{ 110-1,  50-1 },
	{ 130-1,  50-1 },
	{ 160-1, 160-1 },
};

// スペクトルのカウンタアップ値
static const u8 SpectreCountUp[] = {
	1, 2, 2, 2, 4
};

// サーモグラフィー配置チェック（１ビット目が左）
static const u16 ThermographyPutCheck[] = {
	0x7c1f,
	0x7007,
	0x6003,
	0x4001,
	0x4001,
	0x0000,
	0x0000,
	0x0000,
	0x0000,
	0x0000,
	0x4001,
	0x4001,
	0x6003,
	0x7007,
	0x7c1f,
};

// サーモグラフィーキャラ
static const u16 ThermographyChar[] = {
	(THERMOGRAPHY_CHAR+ 0)+(0x3000), (THERMOGRAPHY_CHAR+ 1)+(0x2000),
	(THERMOGRAPHY_CHAR+ 2)+(0x2000), (THERMOGRAPHY_CHAR+ 3)+(0x2000),
	(THERMOGRAPHY_CHAR+ 4)+(0x2000), (THERMOGRAPHY_CHAR+ 5)+(0x2000),
	(THERMOGRAPHY_CHAR+ 6)+(0x2000), (THERMOGRAPHY_CHAR+ 7)+(0x2000),
	(THERMOGRAPHY_CHAR+ 8)+(0x2000), (THERMOGRAPHY_CHAR+ 9)+(0x2000),
	(THERMOGRAPHY_CHAR+10)+(0x2000), (THERMOGRAPHY_CHAR+11)+(0x2000),
	(THERMOGRAPHY_CHAR+12)+(0x2000), (THERMOGRAPHY_CHAR+13)+(0x2000),
	(THERMOGRAPHY_CHAR+14)+(0x2000), (THERMOGRAPHY_CHAR+15)+(0x2000),
};

// BMPWIN
static const BMPWIN_DAT BmpWinData[] =
{
	{	//「しらべる」
		BMPWIN_CHECK_FRM, BMPWIN_CHECK_PX, BMPWIN_CHECK_PY,
		BMPWIN_CHECK_SX, BMPWIN_CHECK_SY, BMPWIN_CHECK_PAL, BMPWIN_CHECK_CGX
	},
	{	//「はなす」
		BMPWIN_TALK_FRM, BMPWIN_TALK_PX, BMPWIN_TALK_PY,
		BMPWIN_TALK_SX, BMPWIN_TALK_SY, BMPWIN_TALK_PAL, BMPWIN_TALK_CGX
	},
	{	//「つり」
		BMPWIN_FISH_FRM, BMPWIN_FISH_PX, BMPWIN_FISH_PY,
		BMPWIN_FISH_SX, BMPWIN_FISH_SY, BMPWIN_FISH_PAL, BMPWIN_FISH_CGX
	},
	{	//「つぎへ」
		BMPWIN_NEXT_FRM, BMPWIN_NEXT_PX, BMPWIN_NEXT_PY,
		BMPWIN_NEXT_SX, BMPWIN_NEXT_SY, BMPWIN_NEXT_PAL, BMPWIN_NEXT_CGX
	},
	{	//「もどる」
		BMPWIN_RET_FRM, BMPWIN_RET_PX, BMPWIN_RET_PY,
		BMPWIN_RET_SX, BMPWIN_RET_SY, BMPWIN_RET_PAL, BMPWIN_RET_CGX
	}
};

// 表示ＯＢＪパラメータ
static const u8 ClaAddParam[][4] =
{	// x, y, pri, anm
	{ 168, 144, 0, 5 },	// Ａボタン
	{ 184,  86, 1, 3 },	// Ｂボタン
	{ 210,  94, 0, 7 },	// ダッシュマーク
	{ 200,   8, 0, 8 },	// 戻るボタン
};


//--------------------------------------------------------------------------------------------
/**
 * ダウジングマシン初期化
 *
 * @param	bgl
 * @param	sub_panel_trg
 * @param	fsys
 * @param	work
 *
 * @return	TCB_PTR
 */
//--------------------------------------------------------------------------------------------
TCB_PTR DowsingSublcdInit(
			GF_BGL_INI * bgl, u16 * sub_panel_trg, FIELDSYS_WORK * fsys, void * work )
{
	TCB_PTR	tcb;
	DM_WORK * wk;
	ARCHANDLE * ah;

	// 異様にデカいがポケッチの合計と同じにしておく
	sys_CreateHeap( HEAPID_BASE_APP, HEAPID_SUBLCD_MENU,  0x18000 );

	G2S_BlendNone();

	tcb = PMDS_taskAdd( MainTask, sizeof(DM_WORK), 10, HEAPID_SUBLCD_MENU );
	wk  = TCB_GetWork( tcb );

	wk->bgl    = bgl;
	wk->sp_trg = sub_panel_trg;
	wk->fsys   = fsys;
	wk->scr_wk = work;
	wk->tcb    = tcb;
//	wk->list   = NULL;
//	wk->seq    = 0;

	wk->radar_hit = FALSE;

	// 初期Ａボタン文字設定
	wk->action = FieldCheck_FrontAction( wk->fsys );

	//「はなす」アクションなら
	if( wk->action == 1 ){
		FIELD_OBJ_PTR obj;
		// 目の前のOBJを取得
		SXY_HeroFrontObjGet( wk->fsys, &obj );
		//「しらべる」アクションにフック
		if( FieldSublcd_FrontEventCheck( FieldOBJ_EventIDGet(obj) ) == TRUE ||
			FieldSublcd_ObjNoTalkCheck( FieldOBJ_OBJCodeGet(obj) ) == TRUE ){
			wk->action = 0;
		}
	}

	ah = ArchiveDataHandleOpen( ARC_DOWSING_GRA, HEAPID_SUBLCD_MENU );

	VramInit();
	BgInit( bgl );
	BgGraLoad( wk, ah );
	MsgInit( wk );
	BmpInit( wk );
	ObjInit( wk, ah );

	ArchiveDataHandleClose( ah );

	return tcb;
}

//--------------------------------------------------------------------------------------------
/**
 * ダウジングマシン終了リクエスト
 *
 * @param	bgl		GF_BGL_INI
 * @param	tcb		TCB_PTR
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void DowsingSublcdQuitReq( GF_BGL_INI * bgl,  TCB_PTR tcb )
{
	DM_WORK * wk = TCB_GetWork( tcb );

	HideItemListExit( wk );

	ObjExit( wk );
	BmpExit( wk );
	MsgExit( wk );
	BgExit( wk->bgl );

	// タスク消去
	PMDS_taskDel( tcb );

	sys_DeleteHeap( HEAPID_SUBLCD_MENU );
}

//--------------------------------------------------------------------------------------------
/**
 * ダウジングマシン終了待ち
 *
 * @param	bgl		GF_BGL_INI
 *
 * @retval	"TRUE = 終了"
 * @retval	"FALSE = それ以外"
 */
//--------------------------------------------------------------------------------------------
BOOL DowsingSublcdQuitWait( GF_BGL_INI * bgl )
{
	return TRUE;
}


//--------------------------------------------------------------------------------------------
/**
 * VRAM初期化
 *
 * @param	none
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void VramInit(void)
{
	GX_SetBankForSubBG( GX_VRAM_SUB_BG_32_H );
	GX_SetBankForSubOBJ( GX_VRAM_SUB_OBJ_16_I );
	GXS_SetOBJVRamModeChar( GX_OBJVRAMMODE_CHAR_1D_32K );
}

//--------------------------------------------------------------------------------------------
/**
 * BG初期化
 *
 * @param	bgl		GF_BGL_INI
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BgInit( GF_BGL_INI * bgl )
{
	GXS_SetGraphicsMode( GX_BGMODE_0 );

	{
		GF_BGL_BGCNT_HEADER head = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0x7800, GX_BG_CHARBASE_0x04000, GX_BG_EXTPLTT_01,
			0, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( bgl, GF_BGL_FRAME0_S, &head, GF_BGL_MODE_TEXT );
		GF_BGL_ClearCharSet( GF_BGL_FRAME0_S, 32, 0, HEAPID_SUBLCD_MENU );
		GF_BGL_ScrClear( bgl, GF_BGL_FRAME0_S );
	}
	{
		GF_BGL_BGCNT_HEADER head = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0x7000, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			1, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( bgl, GF_BGL_FRAME1_S, &head, GF_BGL_MODE_TEXT );
	}
	{
		GF_BGL_BGCNT_HEADER head = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0x6800, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			2, 0, 0, FALSE

		};
		GF_BGL_BGControlSet( bgl, GF_BGL_FRAME2_S, &head, GF_BGL_MODE_TEXT );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * BG解放
 *
 * @param	bgl		GF_BGL_INI
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BgExit( GF_BGL_INI * bgl )
{
	GF_BGL_BGControlExit( bgl, GF_BGL_FRAME2_S );
	GF_BGL_BGControlExit( bgl, GF_BGL_FRAME1_S );
	GF_BGL_BGControlExit( bgl, GF_BGL_FRAME0_S );
}

//--------------------------------------------------------------------------------------------
/**
 * BGグラフィックロード
 *
 * @param	wk		ダウジング画面ワーク
 * @param	ah		アークハンドル
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BgGraLoad( DM_WORK * wk, ARCHANDLE * ah )
{
	ArcUtil_HDL_BgCharSet(
		ah, NARC_dowsing_gra_dow_bg_lz_NCGR,
		wk->bgl, GF_BGL_FRAME1_S, 0, 0, TRUE, HEAPID_SUBLCD_MENU );
	ArcUtil_HDL_ScrnSet(
		ah, NARC_dowsing_gra_dow_bg01_lz_NSCR,
		wk->bgl, GF_BGL_FRAME1_S, 0, 0, TRUE, HEAPID_SUBLCD_MENU );
	ArcUtil_HDL_ScrnSet(
		ah, NARC_dowsing_gra_dow_bg02_lz_NSCR,
		wk->bgl, GF_BGL_FRAME2_S, 0, 0, TRUE, HEAPID_SUBLCD_MENU );

	ArcUtil_HDL_PalSet(
		ah, NARC_dowsing_gra_dow_bg_NCLR, PALTYPE_SUB_BG, 0, 0, HEAPID_SUBLCD_MENU );
}

//--------------------------------------------------------------------------------------------
/**
 * 表示文字列初期化
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void MsgInit( DM_WORK * wk )
{
	MSGDATA_MANAGER * mman = MSGMAN_Create(
								MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_fieldmenu_dat, HEAPID_SUBLCD_MENU );

	//「はなす」
	wk->str[DM_MSG_TALK] = MSGMAN_AllocString( mman, msg_menu_17 );
	//「しらべる」
	wk->str[DM_MSG_CHECK] = MSGMAN_AllocString( mman, msg_menu_18 );
	//「つり」
	wk->str[DM_MSG_FISH] = MSGMAN_AllocString( mman, msg_menu_22 );
	//「つぎへ」
	wk->str[DM_MSG_NEXT] = MSGMAN_AllocString( mman, msg_menu_23 );
	//「もどる」
	wk->str[DM_MSG_RET] = MSGMAN_AllocString( mman, msg_menu_21 );

	MSGMAN_Delete( mman );
}

//--------------------------------------------------------------------------------------------
/**
 * 表示文字列解放
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void MsgExit( DM_WORK * wk )
{
	u32	i;

	for( i=0; i<DM_MSG_MAX; i++ ){
		STRBUF_Delete( wk->str[i] );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * BMP初期化
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BmpInit( DM_WORK * wk )
{
	u32	i;

	// タッチフォント読み込み
	FontProc_LoadFont( FONT_TOUCH, HEAPID_SUBLCD_MENU );

	for( i=0; i<DM_MSG_MAX; i++ ){
		GF_BGL_BmpWinAddEx( wk->bgl, &wk->win[i], &BmpWinData[i] );
		GF_BGL_BmpWinDataFill( &wk->win[i], 0 );
		GF_STR_PrintColor(
			&wk->win[i], FONT_TOUCH, wk->str[i], 0, 0,
			MSG_NO_PUT, GF_PRINTCOLOR_MAKE(15,1,0), NULL );
		GF_BGL_BmpWinCgxOn( &wk->win[i] );
	}
	GF_BGL_BmpWinOnVReq( &wk->win[ ButtonStrTbl[wk->action] ] );
	GF_BGL_BmpWinOnVReq( &wk->win[DM_MSG_RET] );
}

//--------------------------------------------------------------------------------------------
/**
 * BMP解放
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BmpExit( DM_WORK * wk )
{
	u32	i;

	for( i=0; i<DM_MSG_MAX; i++ ){
		GF_BGL_BmpWinDel( &wk->win[i] );
	}

	// タッチフォントアンロード
	FontProc_UnloadFont( FONT_TOUCH );
}


//--------------------------------------------------------------------------------------------
/**
 * OBJ初期化
 *
 * @param	wk		ダウジング画面ワーク
 * @param	ah		アークハンドル
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjInit( DM_WORK * wk, ARCHANDLE * ah )
{
	u32	i;

	// セルアクター初期化
	wk->claSet = CLACT_U_SetEasyInit( DM_CLA_MAX, &wk->rndDat, HEAPID_SUBLCD_MENU );

	CLACT_U_SetSubSurfaceMatrix( &wk->rndDat, 0, DM_SUB_ACTOR_DISTANCE );

	ClaResManInit( wk );

	ClaMenuAdd( wk );
	ClaDowsingAdd( wk, ah );
}

//--------------------------------------------------------------------------------------------
/**
 * OBJ解放
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjExit( DM_WORK * wk )
{
	ClaDowsingDel( wk );
	ClaMenuDel( wk );

	ClaResManExit( wk );
	CLACT_DestSet( wk->claSet );
}

//--------------------------------------------------------------------------------------------
/**
 * リソースマネージャー初期化
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaResManInit( DM_WORK * wk )
{
	u32	i;

	for( i=0; i<DM_RES_TYPE_MAX; i++ ){
		wk->resMan[i] = CLACT_U_ResManagerInit( DM_RES_MAN_MAX, i, HEAPID_SUBLCD_MENU );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * リソースマネージャ削除
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaResManExit( DM_WORK * wk )
{
	u32	i;

	for( i=0; i<DM_RES_TYPE_MAX; i++ ){
		CLACT_U_ResManagerDelete( wk->resMan[i] );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * リソース読み込み
 *
 * @param	res_obj			リソースオブジェ
 * @param	res_man			リソースマネージャ
 * @param	ah				アークハンドル
 * @param	chr				キャラクタデータインデックス
 * @param	pal				パレットデータインデックス
 * @param	cel				セルデータインデックス
 * @param	anm				セルアニメインデックス
 * @param	comm_res_chr	キャラリソースＩＤ
 * @param	comm_res_pal	パレットリソースＩＤ
 * @param	comm_res_cel	セルリソースＩＤ
 * @param	comm_res_anm	アニメリソースＩＤ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaResLoadHandle(
				CLACT_U_RES_OBJ_PTR * res_obj,
				CLACT_U_RES_MANAGER_PTR * res_man,
				ARCHANDLE * ah,
				int chr,
				int pal,
				int cel,
				int anm,
				int pal_max,
				int comm_res_chr,
				int comm_res_pal,
				int comm_res_cel,
				int comm_res_anm )
{
	// キャラクタデータ読み込み
	res_obj[CLACT_U_CHAR_RES] = CLACT_U_ResManagerResAddArcChar_ArcHandle(
									res_man[CLACT_U_CHAR_RES],
									ah,
									chr,
									TRUE,
									comm_res_chr,
									NNS_G2D_VRAM_TYPE_2DSUB,
									HEAPID_SUBLCD_MENU );

	// 転送
	CLACT_U_CharManagerSetAreaCont( res_obj[CLACT_U_CHAR_RES] );
	// グラフィックデータだけ破棄
	CLACT_U_ResManagerResOnlyDelete( res_obj[CLACT_U_CHAR_RES] );

	// パレットデータ読み込み
	res_obj[CLACT_U_PLTT_RES] = CLACT_U_ResManagerResAddArcPltt_ArcHandle(
									res_man[CLACT_U_PLTT_RES],
									ah,
									pal,
									FALSE,
									comm_res_pal,
									NNS_G2D_VRAM_TYPE_2DSUB,
									pal_max,
									HEAPID_SUBLCD_MENU );
	// 転送
	CLACT_U_PlttManagerSetCleanArea( res_obj[CLACT_U_PLTT_RES] );
	// グラフィックデータだけ破棄
	CLACT_U_ResManagerResOnlyDelete( res_obj[CLACT_U_PLTT_RES] );

	// セルデータ読み込み
	res_obj[CLACT_U_CELL_RES] = CLACT_U_ResManagerResAddArcKindCell_ArcHandle(
									res_man[CLACT_U_CELL_RES],
									ah,
									cel,
									TRUE,
									comm_res_cel,
									CLACT_U_CELL_RES,
									HEAPID_SUBLCD_MENU );

	// セルアニメデータ読み込み
	res_obj[CLACT_U_CELLANM_RES] = CLACT_U_ResManagerResAddArcKindCell_ArcHandle(
									res_man[CLACT_U_CELLANM_RES],
									ah,
									anm,
									TRUE,
									comm_res_anm,
									CLACT_U_CELLANM_RES,
									HEAPID_SUBLCD_MENU );
}

//--------------------------------------------------------------------------------------------
/**
 * セルアクターヘッダー作成
 *
 * @param	res_obj		リソースオブジェ
 * @param	res_man		リソースマネージャー
 * @param	head		ヘッダー作成先
 * @param	bg_pri		ＢＧとのプライオリティ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaHeaderMake(
				CLACT_U_RES_OBJ_PTR * res_obj,
				CLACT_U_RES_MANAGER_PTR * res_man,
				CLACT_HEADER * head,
				int bg_pri )
{
	CLACT_U_MakeHeader(
		head,
		CLACT_U_ResManagerGetResObjID( res_obj[CLACT_U_CHAR_RES] ),
		CLACT_U_ResManagerGetResObjID( res_obj[CLACT_U_PLTT_RES] ),
		CLACT_U_ResManagerGetResObjID( res_obj[CLACT_U_CELL_RES] ),
		CLACT_U_ResManagerGetResObjID( res_obj[CLACT_U_CELLANM_RES] ),
		CLACT_U_HEADER_DATA_NONE,
		CLACT_U_HEADER_DATA_NONE,
		0,
		bg_pri,
		res_man[CLACT_U_CHAR_RES],
		res_man[CLACT_U_PLTT_RES],
		res_man[CLACT_U_CELL_RES],
		res_man[CLACT_U_CELLANM_RES],
		NULL,
		NULL );
}

//--------------------------------------------------------------------------------------------
/**
 * セルアクター追加
 *
 * @param	wk			ダウジング画面ワーク
 * @param	objID		OBJ ID
 * @param	hed			ヘッダー
 * @param	prm			OBJ表示パラメータ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaAdd( DM_WORK * wk, u32 objID, CLACT_HEADER * hed, const u8 * prm )
{
	CLACT_ADD add;

	add.ClActSet    = wk->claSet;
	add.ClActHeader = hed;

	add.mat.x       = (prm[0]<<FX32_SHIFT);
	add.mat.y       = (prm[1]<<FX32_SHIFT) + DM_SUB_ACTOR_DISTANCE;
	add.mat.z       = 0;

	add.sca.x       = FX32_ONE;
	add.sca.y       = FX32_ONE;
	add.sca.z       = FX32_ONE;

	add.rot         = 0;
	add.pri         = prm[2];
	add.DrawArea    = NNS_G2D_VRAM_TYPE_2DSUB;
	add.heap        = HEAPID_SUBLCD_MENU;

	wk->actWork[objID] = CLACT_Add( &add );

	CLACT_AnmChg( wk->actWork[objID], prm[3] );
}

//--------------------------------------------------------------------------------------------
/**
 * フィールドメニューに格納されているＯＢＪを追加
 *
 * @param	wk			ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaMenuAdd( DM_WORK * wk )
{
	ARCHANDLE * ah;
	CLACT_HEADER	hed;

	ah = ArchiveDataHandleOpen( ARC_SUBLCDMENU_GRA, HEAPID_SUBLCD_MENU );

	ClaResLoadHandle(
		wk->resObj[DM_RES_MAN_BUTTON],
		wk->resMan,
		ah,
		NARC_poketch_menu_button_lz_ncgr,
		NARC_poketch_udmenu_bg_nclr,
		NARC_poketch_menu_button_lz_ncer,
		NARC_poketch_menu_button_lz_nanr,
		4,
		DM_RES_ID_BUTTON,
		DM_RES_ID_BUTTON,
		DM_RES_ID_BUTTON,
		DM_RES_ID_BUTTON );

	ArchiveDataHandleClose( ah );

	ClaHeaderMake( wk->resObj[DM_RES_MAN_BUTTON], wk->resMan, &hed, 1 );

	ClaAdd( wk, DM_CLA_A_BUTTON, &hed, ClaAddParam[DM_CLA_A_BUTTON] );
	ClaAdd( wk, DM_CLA_B_BUTTON, &hed, ClaAddParam[DM_CLA_B_BUTTON] );
	ClaAdd( wk, DM_CLA_B_DASH, &hed, ClaAddParam[DM_CLA_B_DASH] );
	ClaAdd( wk, DM_CLA_RET, &hed, ClaAddParam[DM_CLA_RET] );

	// ダッシュマーク切り替え
	if( Player_DashBitGet( Player_FieldSysWorkPlayerGet(wk->fsys) ) == 0 ){
		CLACT_AnmChg( wk->actWork[DM_CLA_B_BUTTON], 3 );
		CLACT_AnmChg( wk->actWork[DM_CLA_B_DASH], 11 );
	}else{
		CLACT_AnmChg( wk->actWork[DM_CLA_B_BUTTON], 4 );
		CLACT_AnmChg( wk->actWork[DM_CLA_B_DASH], 7 );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * フィールドメニューに格納されているＯＢＪを削除
 *
 * @param	wk			ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaMenuDel( DM_WORK * wk )
{
	CLACT_Delete( wk->actWork[DM_CLA_A_BUTTON] );
	CLACT_Delete( wk->actWork[DM_CLA_B_BUTTON] );
	CLACT_Delete( wk->actWork[DM_CLA_B_DASH] );

	CLACT_U_CharManagerDelete( wk->resObj[DM_RES_MAN_BUTTON][CLACT_U_CHAR_RES] );
	CLACT_U_PlttManagerDelete( wk->resObj[DM_RES_MAN_BUTTON][CLACT_U_PLTT_RES] );
}

//--------------------------------------------------------------------------------------------
/**
 * ダウジング画面のＯＢＪを追加
 *
 * @param	wk		ダウジング画面ワーク
 * @param	ah		アークハンドル
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaDowsingAdd( DM_WORK * wk, ARCHANDLE * ah )
{
	CLACT_HEADER	hed;
	u32	i;
	u8 prm[] = { 0, 0, 0, 0 };

	ClaResLoadHandle(
		wk->resObj[DM_RES_MAN_DOWSING],
		wk->resMan,
		ah,
		NARC_dowsing_gra_dow_obj_lz_NCGR,
		NARC_dowsing_gra_dow_obj_NCLR,
		NARC_dowsing_gra_dow_obj_lz_NCER,
		NARC_dowsing_gra_dow_obj_lz_NANR,
		9,
		DM_RES_ID_DOWSING,
		DM_RES_ID_DOWSING,
		DM_RES_ID_DOWSING,
		DM_RES_ID_DOWSING );

	ClaHeaderMake( wk->resObj[DM_RES_MAN_DOWSING], wk->resMan, &hed, 2 );

	for( i=0; i<DM_CLA_SPECTRE_MAX; i++ ){
		ClaAdd( wk, DM_CLA_SPECTRE+i, &hed, prm );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ダウジング画面のＯＢＪを削除
 *
 * @param	wk		ダウジング画面ワーク
 * @param	ah		アークハンドル
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClaDowsingDel( DM_WORK * wk )
{
	u32	i;

	for( i=0; i<DM_CLA_SPECTRE_MAX; i++ ){
		CLACT_Delete( wk->actWork[DM_CLA_SPECTRE+i] );
	}

	CLACT_U_CharManagerDelete( wk->resObj[DM_RES_MAN_DOWSING][CLACT_U_CHAR_RES] );
	CLACT_U_PlttManagerDelete( wk->resObj[DM_RES_MAN_DOWSING][CLACT_U_PLTT_RES] );
}


//--------------------------------------------------------------------------------------------
/**
 * メインタスク
 *
 * @param	tcb		TCB_PTR
 * @param	wk		ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void MainTask( TCB_PTR tcb, void * work )
{
	DM_WORK * wk;

	wk = work;

	if( wk->fsys->sublcd_menu_lock_passive ){
		// 動作可能状態になったらパッシブロックOFF
		if( FieldMap_CheckHeroMove(wk->fsys) ){
			wk->fsys->sublcd_menu_lock_passive = 0;
		}
	}

	if( wk->radar_hit == FALSE ){
		if( GF_TP_HitTrg( RadarHitTbl ) != TP_HIT_NONE ){
			wk->radar_hit = TRUE;
		}
	}

#if BTS_5496_FIX
	if( FieldEvent_Check( wk->fsys ) == TRUE ||
		GF_TP_HitCont( RadarHitTbl ) == TP_HIT_NONE ||
		wk->radar_hit == FALSE ){
#else
	if( FieldEvent_Check( wk->fsys ) == TRUE || GF_TP_HitCont( RadarHitTbl ) == TP_HIT_NONE ){
#endif
		SpectreTouchCount( wk, -1 );
		ThermographyCount( wk, FALSE );
		wk->spc_flg   = 0;
		wk->se_cnt    = 0;
		wk->pitch     = 0;
		wk->radar_hit = FALSE;
		Snd_SeStopBySeqNo( SE_DOWSING_RADAR, 0 );
//		wk->r_flg = 0;
	}else{
/*
		if( TouchPosCheck( wk ) == FALSE ){
			SpectreMoveWorkMake( wk );
		}
*/
		if( wk->radar_hit == TRUE ){
			TouchPosCheck( wk );
//			GlobalRadMake( wk );
			SpectreMoveWorkMake( wk );
			SpectreTouchCount( wk, 1 );
			ThermographyCount( wk, TRUE );
			SearchSePlay( wk );
		}
	}

/*
	if( sys.cont & PAD_BUTTON_R ){
		if( wk->pich + 1 <= 16 ){
			wk->pich += 1;
		}
	}
	if( sys.cont & PAD_BUTTON_L ){
		if( wk->pich - 1 >= -15 ){
			wk->pich -= 1;
		}
	}
*/

	SpectreAnime( wk );
	SpectreMove( wk );

	TalkButton( wk );
	DashButton( wk );
	RetButton( wk );

	CLACT_Draw( wk->claSet );
}

//--------------------------------------------------------------------------------------------
/**
 * 隠しアイテムリスト作成
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void HideItemListCreate( DM_WORK * wk )
{
	wk->list = HideItem_CreateList( wk->fsys, HEAPID_SUBLCD_MENU );
}

//--------------------------------------------------------------------------------------------
/**
 * 隠しアイテムリスト削除
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void HideItemListExit( DM_WORK * wk )
{
	if( wk->list != NULL ){
		sys_FreeMemoryEz( wk->list );
		wk->list = NULL;
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 最も近い隠しアイテムを取得
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void NearHideItemGet( DM_WORK * wk )
{
	u16	m, n;
	u32	i;

	HideItemListCreate( wk );

	wk->item_flg = FALSE;
	i = 0;

	while( 1 ){
		if( wk->list[i].response == HIDE_LIST_RESPONSE_NONE ){
			break;
		}

		if( wk->item_flg == FALSE ){
			m = abs( wk->list[i].gx ) + abs( wk->list[i].gz );
			wk->item_px = wk->list[i].gx;
			wk->item_py = wk->list[i].gz;
			wk->item_flg = TRUE;
		}else{
			n = abs( wk->list[i].gx ) + abs( wk->list[i].gz );
			if( m > n ){
				m = n;
				wk->item_px = wk->list[i].gx;
				wk->item_py = wk->list[i].gz;
			}
		}
		i++;
	}

	HideItemListExit( wk );
}

//--------------------------------------------------------------------------------------------
/**
 * スペクトル表示座標作成
 *
 * @param	vec		座標格納場所
 * @param	rad		角度
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectrePosMake( VecFx32 * vec, u32 rad )
{
/*
	vec->x = FX_MUL( FX16_TO_FX32(FX_CosIdx(rad)), SPECTRE_R_FX32 ) + SPECTRE_CX_FX32;
	vec->y = FX_MUL( FX16_TO_FX32(FX_SinIdx(rad)), SPECTRE_R_FX32 ) + SPECTRE_CY_FX32 + DM_SUB_ACTOR_DISTANCE;
*/
	vec->x = FX_MUL( Cos360R(rad), SPECTRE_R_FX32 ) + SPECTRE_CX_FX32;
	vec->y = FX_MUL( Sin360R(rad), SPECTRE_R_FX32 ) + SPECTRE_CY_FX32 + DM_SUB_ACTOR_DISTANCE;
}

//--------------------------------------------------------------------------------------------
/**
 * スペクトルの表示に使用する角度を取得
 *
 * @param	px		Ｘ座標
 * @param	py		Ｙ座標
 *
 * @return	FX_Atan2Idx()
 */
//--------------------------------------------------------------------------------------------
static u16 SpectreAtan2Idx( s32 px, s32 py )
{
	fx32 ax, ay;

	ax = ( px - SPECTRE_CX ) << FX32_SHIFT;
	ay = ( py - SPECTRE_CY ) << FX32_SHIFT;

	return FX_Atan2Idx( ay, ax );
}
/*
static fx16 SpectreAtan2( s32 px, s32 py )
{
	fx32 ax, ay;

	ax = ( px - SPECTRE_CX ) << FX32_SHIFT;
	ay = ( py - SPECTRE_CY ) << FX32_SHIFT;

	return FX_Atan2( ay, ax );
}
*/

//--------------------------------------------------------------------------------------------
/**
 * スペクトルの表示に使用する角度を取得（アイテム位置）
 *
 * @param	px		Ｘ座標
 * @param	py		Ｙ座標
 *
 * @return	FX_Atan2Idx()
 */
//--------------------------------------------------------------------------------------------
static u16 ItemAtan2Idx( s32 px, s32 py )
{
	fx32 ax, ay;

	ax = px << FX32_SHIFT;
	ay = py << FX32_SHIFT;

	return FX_Atan2Idx( ay, ax );
}

//--------------------------------------------------------------------------------------------
/**
 * FX_Atan2Idx()を360度に変換
 *
 * @param	atan2	FX_Atan2Idx()の戻り値
 *
 * @return	FX_Atan2Idx()を360度に変換した値
 */
//--------------------------------------------------------------------------------------------
static u32 Atan2Idx360( u32 atan2 )
{
	atan2 = ( ( ( atan2 << 16 ) / 0x10000 ) * 360 ) >> 16;
	return atan2;
}

//--------------------------------------------------------------------------------------------
/**
 * アイテムがゾーン内に無いときのスペクトル動作
 *
 * @param	wk		スペクトル動作ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectreMoveMake01( SPECTRE_WORK * wk )
{
//	wk->prm = ( ( ( wk->pos + wk->now * 5 ) << 16 ) / 6 ) >> 16;
	wk->prm = ( wk->pos + wk->now * 5 ) / 6;
}

//--------------------------------------------------------------------------------------------
/**
 * アイテムがゾーン内に無いときのスペクトル移動先
 *
 * @param	wk		スペクトル動作ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectreMoveWorkMake01( DM_WORK * wk )
{
	u32	atan2;
	u32	i;

	atan2 = Atan2Idx360( SpectreAtan2Idx(wk->tpx,wk->tpy) );

	// 0
	wk->spc[0].pos = atan2;
	// 1
	wk->spc[1].pos = atan2 + 5 * PAI / 3;
//	wk->spc[1].pos = atan2 * 1.5 + 5 * PAI / 3;
	// 2
	wk->spc[2].pos = atan2 + 2 * PAI / 3;
//	wk->spc[2].pos = atan2 * 0.8 + 2 * PAI / 3;
	// 3
	wk->spc[3].pos = atan2 + 6 * PAI / 5;
//	wk->spc[3].pos = atan2 * 1.2 + 6 * PAI / 5;

	wk->spc_move_cnt = 6;
}

//--------------------------------------------------------------------------------------------
/**
 * ゾーン内のアイテムが35x35の範囲にないときのスペクトル動作
 *
 * @param	wk		スペクトル動作ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectreMoveMake02( SPECTRE_WORK * wk )
{
	wk->prm = ( wk->pos + wk->now * 3 ) / 4;
}

//--------------------------------------------------------------------------------------------
/**
 * ゾーン内のアイテムが35x35の範囲にないときのスペクトル移動先
 *
 * @param	wk		スペクトル動作ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectreMoveWorkMake02( DM_WORK * wk )
{
	u32	atan2;
	u32	iatn2;

	atan2 = Atan2Idx360( SpectreAtan2Idx(wk->tpx,wk->tpy) );
	iatn2 = Atan2Idx360( ItemAtan2Idx(wk->item_px,wk->item_py) );

	// 0
	wk->spc[0].pos = ( atan2 * 3 + iatn2 ) / 4;
	// 1
	wk->spc[1].pos = ( ( atan2 + PAI/6 ) * 3 + ( iatn2 + 2*PAI/3 ) ) / 4;
	// 2
	wk->spc[2].pos = ( ( atan2 - PAI/5 ) * 3 + ( iatn2 - 3*PAI/4 ) ) / 4;
	// 3
	wk->spc[3].pos = ( ( atan2 + PAI/2 ) * 3 + ( iatn2 + 1*PAI/2 ) ) / 4;

	wk->spc_move_cnt = 4;
}

//--------------------------------------------------------------------------------------------
/**
 * ゾーン内のアイテムが35x35の範囲にあるときのスペクトル動作
 *
 * @param	wk		スペクトル動作ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectreMoveMake03( SPECTRE_WORK * wk )
{
	wk->prm = ( wk->pos + wk->now * 2 ) / 3;
}

//--------------------------------------------------------------------------------------------
/**
 * ゾーン内のアイテムが35x35の範囲にあるときのスペクトル移動先
 *
 * @param	wk		スペクトル動作ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectreMoveWorkMake03( DM_WORK * wk )
{
	u32	atan2;
	u32	iatn2;

	atan2 = Atan2Idx360( SpectreAtan2Idx(wk->tpx,wk->tpy) );
	iatn2 = Atan2Idx360( ItemAtan2Idx(wk->item_px,wk->item_py) );

	// 0
	wk->spc[0].pos = ( atan2 * 2 + iatn2 ) / 3;
	// 1
	wk->spc[1].pos = ( ( atan2 + PAI/6 ) * 2 + ( iatn2 + 3*PAI/4 ) ) / 3;
	// 2
	wk->spc[2].pos = ( ( atan2 - PAI/5 ) * 2 + ( iatn2 - 2*PAI/3 ) ) / 3;
	// 3
	wk->spc[3].pos = ( ( atan2 + PAI/2 ) * 2 + ( iatn2 + 1*PAI/3 ) ) / 3;

	wk->spc_move_cnt = 3;
}

//--------------------------------------------------------------------------------------------
/**
 * ゾーン内のアイテムが25x25の範囲にあるときのスペクトル動作
 *
 * @param	wk		スペクトル動作ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectreMoveMake04( SPECTRE_WORK * wk )
{
	wk->prm = ( wk->pos + wk->now ) / 2;
}

//--------------------------------------------------------------------------------------------
/**
 * ゾーン内のアイテムが25x25の範囲にあるときのスペクトル移動先
 *
 * @param	wk		スペクトル動作ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectreMoveWorkMake04( DM_WORK * wk )
{
	u32	atan2;
	u32	iatn2;

	atan2 = Atan2Idx360( SpectreAtan2Idx(wk->tpx,wk->tpy) );
	iatn2 = Atan2Idx360( ItemAtan2Idx(wk->item_px,wk->item_py) );

	// 0
	wk->spc[0].pos = ( atan2 + iatn2 ) / 3;
	// 1
	wk->spc[1].pos = ( ( atan2 + PAI/6 ) + ( iatn2 + PAI/6 ) ) / 2;
	// 2
	wk->spc[2].pos = ( ( atan2 - PAI/5 ) + ( iatn2 - PAI/5 ) ) / 2;
	// 3
	wk->spc[3].pos = ( ( atan2 + PAI/2 ) + ( iatn2 + PAI/4 ) ) / 2;

	wk->spc_move_cnt = 2;
}

//--------------------------------------------------------------------------------------------
/**
 * ゾーン内のアイテムが17x17の範囲にあるときのスペクトル動作
 *
 * @param	wk		スペクトル動作ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectreMoveMake05( SPECTRE_WORK * wk )
{
	wk->prm = ( wk->pos * 2 + wk->now ) / 3;
}

//--------------------------------------------------------------------------------------------
/**
 * ゾーン内のアイテムが17x17の範囲にあるときのスペクトル移動先
 *
 * @param	wk		スペクトル動作ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectreMoveWorkMake05( DM_WORK * wk )
{
	s32	ipx, ipy;

	ipx = wk->item_px * 8 + SPECTRE_CX;
	ipy = wk->item_py * 8 + SPECTRE_CY;

	// 0
	wk->spc[0].pos = Atan2Idx360( ItemAtan2Idx( ipx-wk->tpx, ipy-wk->tpy ) );
	// 1
	wk->spc[1].pos = Atan2Idx360( ItemAtan2Idx( ipx+10-wk->tpx, ipy+12-wk->tpy ) );
	// 2
	wk->spc[2].pos = Atan2Idx360( ItemAtan2Idx( ipx-12-wk->tpx, ipy-4-wk->tpy ) );
	// 3
	wk->spc[3].pos = Atan2Idx360( ItemAtan2Idx( ipx-8-wk->tpx, ipy-8-wk->tpy ) );

	wk->spc_move_cnt = 3;
}

//--------------------------------------------------------------------------------------------
/**
 * スペクトル動作ワーク作成
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 *
 *	アイテム配置パターンも取得
 */
//--------------------------------------------------------------------------------------------
static void SpectreMoveWorkMake( DM_WORK * wk )
{
	s32	mv;
	u32	i;

	NearHideItemGet( wk );

	if( wk->item_flg == FALSE ){
		SpectreMoveWorkMake01( wk );
		wk->item_pat = 0;
	}else{
		s16	px, py;
		px = abs( wk->item_px );
		py = abs( wk->item_py );
		if( px <= 8 && py <= 8 ){
			SpectreMoveWorkMake05( wk );
			wk->item_pat = 4;
		}else if( px <= 12 && py <= 12 ){
			SpectreMoveWorkMake04( wk );
			wk->item_pat = 3;
		}else if( px <= 17 && py <= 17 ){
			SpectreMoveWorkMake03( wk );
			wk->item_pat = 2;
		}else{
			SpectreMoveWorkMake02( wk );
			wk->item_pat = 1;
		}
	}

	if( wk->spc_flg == 0 ){
		for( i=0; i<DM_CLA_SPECTRE_MAX; i++ ){
			wk->spc[i].now = wk->spc[i].pos;
			wk->spc[i].prm = wk->spc[i].pos;
		}
		wk->spc_flg = 1;
		wk->spc_move_cnt = 1;
	}else{
		for( i=0; i<DM_CLA_SPECTRE_MAX; i++ ){
			wk->spc[i].pos %= 360;
			wk->spc[i].now %= 360;

/*
			if( wk->mv == 2 ){
				if( abs((s32)wk->spc[i].pos-(s32)wk->spc[i].now) >= 180 && wk->spc[i].pos > wk->spc[i].now ){
					wk->spc[i].now += 360;
				}
			}else if( wk->mv == 1 ){
				if( abs((s32)wk->spc[i].pos-(s32)wk->spc[i].now) >= 180 && wk->spc[i].pos < wk->spc[i].now ){
					wk->spc[i].pos += 360;
				}
			}
*/
			if( abs((s32)wk->spc[i].pos-(s32)wk->spc[i].now) >= 180 ){
				if( wk->spc[i].pos > wk->spc[i].now ){
					wk->spc[i].now += 360;
				}else if( wk->spc[i].pos < wk->spc[i].now ){
					wk->spc[i].pos += 360;
				}
			}

//			if( wk->mv != 0 ){
				SpectreMoveMake[wk->item_pat]( &wk->spc[i] );
//			}else{
//				wk->spc[i].now = wk->spc[i].pos;
//				wk->spc[i].prm = wk->spc[i].pos;
//				wk->spc_move_cnt = 1;
//			}
		}
	}
}

//--------------------------------------------------------------------------------------------
/**
 * スペクトル表示カウンタ
 *
 * @param	wk		ダウジング画面ワーク
 * @param	p		カウンタ増減値
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectreTouchCount( DM_WORK * wk, s16 p )
{
	if( p >= 0 ){
		p *= SpectreCountUp[wk->item_pat];
		wk->spc_touch_cnt += p;
		if( wk->spc_touch_cnt > TouchCountMax[wk->item_pat][0] ){
			wk->spc_touch_cnt = TouchCountMax[wk->item_pat][0];
		}
	}else{
		if( wk->spc_touch_cnt > 0 ){
			wk->spc_touch_cnt--;
		}
	}
}

//--------------------------------------------------------------------------------------------
/**
 * スペクトルアニメ作成
 *
 * @param	wk		ダウジング画面ワーク
 * @param	anm		アニメ番号格納場所
 * @param	pal		パレット格納場所
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectreAnmGet( DM_WORK * wk, u16 * anm, u16 * pal )
{
	if( wk->spc_touch_cnt > TouchCountMax[wk->item_pat][0] ){
		wk->spc_touch_cnt = TouchCountMax[wk->item_pat][0];
	}

	*anm = ( wk->spc_touch_cnt / 10 ) & 1;
	*pal = wk->spc_touch_cnt / 20;
}

//--------------------------------------------------------------------------------------------
/**
 * スペクトルアニメ
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectreAnime( DM_WORK * wk )
{
	u32	i;
	u16	anm, pal;

	if( wk->spc_touch_cnt == 0 ){
		for( i=0; i<DM_CLA_SPECTRE_MAX; i++ ){
			CLACT_SetDrawFlag( wk->actWork[DM_CLA_SPECTRE+i], 0 );
		}
	}else{
		SpectreAnmGet( wk, &anm, &pal );

		for( i=0; i<DM_CLA_SPECTRE_MAX; i++ ){
			CLACT_PaletteNoChgAddTransPlttNo( wk->actWork[DM_CLA_SPECTRE+i], pal+1 );
			CLACT_AnmChg( wk->actWork[DM_CLA_SPECTRE+i], anm );
			CLACT_SetDrawFlag( wk->actWork[DM_CLA_SPECTRE+i], 1 );
		}
	}
}

//--------------------------------------------------------------------------------------------
/**
 * スペクトル回転
 *
 * @param	act		セルアクターワーク
 * @param	rad		角度
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectreObjRotation( CLACT_WORK_PTR act, u32 rad )
{
	CLACT_SetRotationAffine( act, RotKeyR(rad), CLACT_AFFINE_DOUBLE );
}

//--------------------------------------------------------------------------------------------
/**
 * スペクトル移動
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SpectreMove( DM_WORK * wk )
{
	VecFx32	vec;
	u32	i;

	if( wk->spc_move_cnt == 0 ){ return; }

	wk->spc_move_cnt--;
/*
		for( i=0; i<DM_CLA_SPECTRE_MAX; i++ ){
			wk->spc[i].now = wk->spc[i].prm;
			SpectrePosMake( &vec, wk->spc[i].now );
			CLACT_SetMatrix( wk->actWork[DM_CLA_SPECTRE+i], &vec );
			SpectreObjRotation( wk->actWork[DM_CLA_SPECTRE+i], wk->spc[i].now );
			SpectreMoveMake[wk->item_pat]( &wk->spc[i] );
		}
*/

	if( wk->spc_move_cnt == 0 ){
		for( i=0; i<DM_CLA_SPECTRE_MAX; i++ ){
			wk->spc[i].now = wk->spc[i].pos;
			SpectrePosMake( &vec, wk->spc[i].now );
			CLACT_SetMatrix( wk->actWork[DM_CLA_SPECTRE+i], &vec );
			SpectreObjRotation( wk->actWork[DM_CLA_SPECTRE+i], wk->spc[i].now );
		}
	}else{
		for( i=0; i<DM_CLA_SPECTRE_MAX; i++ ){
			wk->spc[i].now = wk->spc[i].prm;
			SpectrePosMake( &vec, wk->spc[i].now );
			CLACT_SetMatrix( wk->actWork[DM_CLA_SPECTRE+i], &vec );
			SpectreObjRotation( wk->actWork[DM_CLA_SPECTRE+i], wk->spc[i].now );
			SpectreMoveMake[wk->item_pat]( &wk->spc[i] );
		}
	}
}


//--------------------------------------------------------------------------------------------
/**
 * サーモグラフィカウンタ最大値取得
 *
 * @param	wk		ダウジング画面ワーク
 * @param	x		Ｘ座標
 * @param	y		Ｙ座標
 *
 * @return	カウンタ最大値
 */
//--------------------------------------------------------------------------------------------
static u8 ThermographyTouchCountMaxGet( DM_WORK * wk, u16 x, u16 y )
{
//	fx32 sqrt;
	s32	ipx, ipy;
	s32	ret;

	if( wk->item_pat == 4 ){
/*
		ipx  = wk->item_px + RADAR_CX - x;
		ipy  = wk->item_py + RADAR_CY - y;
		OS_Printf( "ipx = %d, ipy = %d\n", ipx, ipy );
		sqrt = FX_Sqrt( (ipx*ipx+ipy*ipy)<<FX32_SHIFT );
		ret  = 15 - (u32)( sqrt >> FX32_SHIFT );
*/
		ipx = abs( (s32)wk->item_px + RADAR_CX - x );
		ipy = abs( (s32)wk->item_py + RADAR_CY - y );
		ret = 16 - ( ipx + ipy );
		if( ret < 5 ){
			ret = 5;
		}else if( ret > 16 ){
			ret = 16;
		}
		return (u8)( ret * 10 - 1 );
	}
	return TouchCountMax[wk->item_pat][1];
}

//--------------------------------------------------------------------------------------------
/**
 * サーモグラフィ表示カウンタ
 *
 * @param	wk		ダウジング画面ワーク
 * @param	flg		タッチフラグ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ThermographyCount( DM_WORK * wk, BOOL flg )
{
	s16	tpx, tpy;
	s16	i, j;

	if( flg == TRUE ){
		tpx = wk->tpx / 8 - THERMOGRAPHY_PX;
		tpy = wk->tpy / 8 - THERMOGRAPHY_PY;
//	}else{
//		tpx = -32;	// 適当
//		tpy = -32;	// 適当
	}

	for( i=0; i<THERMOGRAPHY_SY; i++ ){
		for( j=0; j<THERMOGRAPHY_SX; j++ ){
			if( ( ThermographyPutCheck[i] & (1<<j) ) == 0 ){
				if( flg == TRUE ){
					if( j >= (tpx-3) && j <= (tpx+3) &&
						i >= (tpy-3) && i <= (tpy+3) &&
						(abs(tpx-j)+abs(tpy-i)) <=4 ){

						u8	max = ThermographyTouchCountMaxGet( wk, j, i );
						if( wk->tg_cnt[i][j] < max ){
							wk->tg_cnt[i][j] += 10;
							if( wk->tg_cnt[i][j] > max ){
								wk->tg_cnt[i][j] = max;
							}
						}else{
							wk->tg_cnt[i][j] = max;
						}
					}else{
						if( wk->tg_cnt[i][j] >= 2 ){
							wk->tg_cnt[i][j] -= 2;
						}else{
							wk->tg_cnt[i][j] = 0;
						}
					}
				}else{
					if( wk->tg_cnt[i][j] >= 2 ){
						wk->tg_cnt[i][j] -= 2;
					}else{
						wk->tg_cnt[i][j] = 0;
					}
				}
				if( wk->tg_cnt[i][j] == 0 ){
					GF_BGL_ScrFill(
						wk->bgl, GF_BGL_FRAME2_S, THERMOGRAPHY_NULL_CHAR,
						THERMOGRAPHY_PX+j, THERMOGRAPHY_PY+i, 1, 1, GF_BGL_SCRWRT_PALIN );
				}else{
					GF_BGL_ScrFill(
						wk->bgl, GF_BGL_FRAME2_S, ThermographyChar[wk->tg_cnt[i][j]/10],
						THERMOGRAPHY_PX+j, THERMOGRAPHY_PY+i, 1, 1, GF_BGL_SCRWRT_PALIN );
				}
			}
		}
	}
	GF_BGL_LoadScreenV_Req( wk->bgl, GF_BGL_FRAME2_S );
}


//--------------------------------------------------------------------------------------------
/**
 * サーチＳＥ再生
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void SearchSePlay( DM_WORK * wk )
{
	s32	tpx, tpy;
	u16	anm, pal;
	s16	pitch;

	SpectreAnmGet( wk, &anm, &pal );

	pitch = DEF_SE_PITCH + ( pal * 2 + anm ) * 64;
	if( wk->item_pat == 4 ){
		tpx = wk->tpx / 8 - THERMOGRAPHY_PX;
		tpy = wk->tpy / 8 - THERMOGRAPHY_PY;
		tpx = abs( (s32)wk->item_px + RADAR_CX - tpx );
		tpy = abs( (s32)wk->item_py + RADAR_CY - tpy );
		pitch += ( ( 16 - ( tpx + tpy ) ) * 64 );
	}
//	Snd_SePitchPlay( SE_DOWSING_RADAR, pitch );

	if( wk->se_cnt == 0 ){
//		Snd_SePlay( SE_DOWSING_RADAR );
		Snd_SePitchPlay( SE_DOWSING_RADAR, pitch );
	}

	if( wk->se_cnt == 10 ){
		wk->se_cnt = 0;
	}else{
		wk->se_cnt++;
	}

	if( wk->pitch != pitch ){
//		Snd_PlayerSetTrackPitchBySeqNo( SE_DOWSING_RADAR, 0xffff, pitch );
		wk->pitch = pitch;
	}
}


//--------------------------------------------------------------------------------------------
/**
 * タッチ座標所得
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @retval	"TRUE = 前回のタッチ位置と同じ"
 * @retval	"FALSE = 前回のタッチ位置と違う"
 */
//--------------------------------------------------------------------------------------------
static BOOL TouchPosCheck( DM_WORK * wk )
{
	u32	x, y;

	GF_TP_GetPointCont( &x, &y );

	if( wk->tpx != x || wk->tpy != y ){
		wk->tpx = x;
		wk->tpy = y;
		return FALSE;
	}
	return TRUE;
}

//--------------------------------------------------------------------------------------------
/**
 * 回転方向取得
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
/*
static void GlobalRadMake( DM_WORK * wk )
{
	if( wk->r_flg == 0 ){
		wk->grad = Atan2Idx360( SpectreAtan2Idx(wk->tpx,wk->tpy) );
		wk->mrad = wk->grad;
		wk->r_flg = 1;
	}else{
		wk->grad = wk->mrad;
		wk->mrad = Atan2Idx360( SpectreAtan2Idx(wk->tpx,wk->tpy) );
//		OS_Printf( "grad = %d, mrad = %d\n", wk->grad, wk->mrad );
	}

	wk->mv = 0;
	if( wk->mrad > wk->grad ){
		if( abs((s32)wk->grad-(s32)wk->mrad) >= 180 ){
			wk->mv = 2;		// 左回り
		}else{
			wk->mv = 1;		// 右周り
		}
	}else if( wk->mrad < wk->grad ){
		if( abs((s32)wk->grad-(s32)wk->mrad) >= 180 ){
			wk->mv = 1;		// 右回り
		}else{
			wk->mv = 2;		// 左回り
		}
	}
}
*/


//--------------------------------------------------------------------------------------------
/**
 * Ａボタンに表示する文字列を変更
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void FieldFrontAction( DM_WORK * wk )
{
	int	action;

	// 「つぎへ」フラグを監視
	if( wk->fsys->sublcd_menu_next_flag == TRUE ){
		action = 4;
	// 主人公が移動できない状態
	}else if( FieldMap_CheckHeroMove(wk->fsys) == FALSE ){
		FIELD_OBJ_PTR	obj;
		int	code;

		obj  = Player_FieldOBJGet( Player_FieldSysWorkPlayerGet(wk->fsys) );
		code = FieldOBJ_OBJCodeGet( obj );

		if( code == FISHINGHERO || code == FISHINGHEROINE ){
			if( FieldOBJ_DrawStatusGet( obj ) == 1 ){
				action = 3;		//「つり」
			}else{
				action = 4;		//「つぎへ」
			}
		}else{
			action = wk->action;
		}
	}else{
		action = FieldCheck_FrontAction( wk->fsys );

		//「はなす」アクションなら
		if( action == 1 ){
			FIELD_OBJ_PTR obj;

			// 目の前のOBJを取得
			SXY_HeroFrontObjGet( wk->fsys, &obj );

			//「しらべる」アクションにフック
			if( FieldSublcd_FrontEventCheck( FieldOBJ_EventIDGet(obj) ) == TRUE ||
				FieldSublcd_ObjNoTalkCheck( FieldOBJ_OBJCodeGet(obj) ) == TRUE ){
				action = 0;
			}
		}
	}

	if( action != wk->action ){
		wk->action = action;
		GF_BGL_BmpWinOnVReq( &wk->win[ ButtonStrTbl[wk->action] ] );
	}
}

//-----------------------------------------------------------------------------
/**
 *	@brief	ボタンのタッチアニメ
 *
 *	@param	TP_HIT_TBL* tp_cont_tbl		GF_TP_SingleHitContに渡すデータテブール
 *	@param	act						対象 CLACT_WORK_PTR
 *	@param	anmseq_normal				通常時に表示するアニメシーケンス
 *	@param	anmseq_down					タッチ時に表示するアニメシーケンス
 *
 *	@retval TRUE:押した
 */
//-----------------------------------------------------------------------------
static BOOL ButtonTouchAnime( const TP_HIT_TBL* tp_cont_tbl, CLACT_WORK_PTR act, u8 anmseq_normal, u8 anmseq_down )
{
	int tp_cont;
	int anm_seq;

	tp_cont = GF_TP_SingleHitCont( tp_cont_tbl );
	anm_seq = CLACT_AnmGet( act );

	// 初回タッチ
	if( tp_cont == 1 && GF_TP_GetTrg() )
	{
		CLACT_AnmChg( act, anmseq_down );
		return TRUE;
	}
	// 継続タッチ
	else if( tp_cont == 1 && anm_seq == anmseq_down )
	{
		return TRUE;
	}
	// 非タッチ
	else
	{
		CLACT_AnmChg( act, anmseq_normal );
	}

	return FALSE;
}

//--------------------------------------------------------------------------------------------
/**
 * 会話ボタン
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 *
 *	フィールドメニューの処理と同じにすること
 */
//--------------------------------------------------------------------------------------------
static void TalkButton( DM_WORK * wk )
{
/*
	if( FieldEvent_Check(wk->fsys) ){
		return;
	}
*/
/*
	// ワイプ中は直前調査を行わない
	if( FieldMap_CheckHeroMove( wk->fsys ) == FALSE ){
		return;
	}
*/
	// フィールドマップメインが動作していればアクションボタン文字列を更新
	if( GameSystem_CheckFieldMain( wk->fsys ) == TRUE ){
		FieldFrontAction( wk );
	}

	// Aボタン押してるかチェック
	if( ButtonTouchAnime( &TalkButtonHitTbl, wk->actWork[DM_CLA_A_BUTTON], 5, 6 ) )
	{
		// 押した処理
		sys.extra_cont = PAD_BUTTON_A;
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ダッシュ切り替えボタン
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 *
 *	フィールドメニューの処理と同じにすること
 */
//--------------------------------------------------------------------------------------------
static void DashButton( DM_WORK * wk )
{
	// 自転車チェック & イベントチェック
	if(	Player_FormGet(wk->fsys->player) == HERO_FORM_CYCLE || EventCheck( wk ) == TRUE ){
		CLACT_SetDrawFlag( wk->actWork[DM_CLA_B_BUTTON], 0 );
		CLACT_SetDrawFlag( wk->actWork[DM_CLA_B_DASH], 0 );
		return;
	}else{
		CLACT_SetDrawFlag( wk->actWork[DM_CLA_B_BUTTON], 1 );
		CLACT_SetDrawFlag( wk->actWork[DM_CLA_B_DASH], 1 );
	}

	if( GF_TP_SingleHitTrg( &DashButtonHitTbl ) == TRUE ){
		// ダッシュモード切替
		PLAYER_STATE_PTR jiki = Player_FieldSysWorkPlayerGet( wk->fsys );
		int	flg = Player_DashBitGet( jiki );
		if( flg == 0 ){
			CLACT_AnmChg( wk->actWork[DM_CLA_B_BUTTON], 4 );
			CLACT_AnmChg( wk->actWork[DM_CLA_B_DASH], 7 );
		}else{
			CLACT_AnmChg( wk->actWork[DM_CLA_B_BUTTON], 3 );
			CLACT_AnmChg( wk->actWork[DM_CLA_B_DASH], 11 );
		}
		Player_DashBitSet( jiki, (flg^1) );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * 戻るボタン
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void RetButton( DM_WORK * wk )
{
	if( EventCheck( wk ) == TRUE ){
		GF_BGL_BmpWinOffVReq( &wk->win[DM_MSG_RET] );
		CLACT_AnmChg( wk->actWork[DM_CLA_RET], 8 );
		CLACT_SetDrawFlag( wk->actWork[DM_CLA_RET], 0 );
	}else{
		GF_BGL_BmpWinOnVReq( &wk->win[DM_MSG_RET] );
		CLACT_SetDrawFlag( wk->actWork[DM_CLA_RET], 1 );

		if( ButtonTouchAnime( &RetButtonHitTbl, wk->actWork[DM_CLA_RET], 8, 9 ) )
		{
			// 押した処理
			wk->fsys->sub_panel_trg = SUBLCD_TOUCH_DOWSING_END;
			KeyTouchStatus_SetTouchOrKey( &wk->fsys->KeyTouchStatus, APP_END_TOUCH );
		}
	}
}

//--------------------------------------------------------------------------------------------
/**
 * イベントチェック
 *
 * @param	wk		ダウジング画面ワーク
 *
 * @retval	"TRUE = イベント中"
 * @retval	"FALSE = それ以外"
 */
//--------------------------------------------------------------------------------------------
static BOOL EventCheck( DM_WORK * wk )
{
	if( FieldEvent_Check( wk->fsys ) == TRUE && wk->fsys->sublcd_menu_lock_passive == 0 ){
		return TRUE;
	}
	return FALSE;
}














//============================================================================================
//============================================================================================
//============================================================================================
//============================================================================================
//============================================================================================
//============================================================================================
//============================================================================================
//	テスト処理
//============================================================================================
//============================================================================================
//============================================================================================
#if 0
static u32 TestMoveMake( u32 pos, u32 now )
{
	return ( ( ( pos + now * 5 ) << 8 ) / 6 ) >> 8;
}

#define	TEST_INIT_RAD	( 10 )
#define	TEST_NEXT_RAD	( 328 )

static void TestFunc(void)
{
	u32	init_rad;
	u32	next_rad;
	u32	i;

	// 0
	init_rad = TEST_INIT_RAD;
	next_rad = TEST_NEXT_RAD;
	OS_Printf( "00: %d(%d) ->", init_rad, init_rad%360 );
	for( i=0; i<6; i++ ){
		init_rad = TestMoveMake( next_rad, init_rad );
		OS_Printf( " %d(%d) ->", init_rad, init_rad%360 );
	}
	OS_Printf( "\n" );

	// 1
	init_rad = TEST_INIT_RAD * 1.5 + 5 * PAI / 3;
	next_rad = TEST_NEXT_RAD * 1.5 + 5 * PAI / 3;
	OS_Printf( "01: %d(%d) ->", init_rad, init_rad%360 );
	for( i=0; i<6; i++ ){
		init_rad = TestMoveMake( next_rad, init_rad );
		OS_Printf( " %d(%d) ->", init_rad, init_rad%360 );
	}
	OS_Printf( "\n" );

	// 2
	init_rad = TEST_INIT_RAD * 0.8 + 2 * PAI / 3;
	next_rad = TEST_NEXT_RAD * 0.8 + 2 * PAI / 3;
	OS_Printf( "02: %d(%d) ->", init_rad, init_rad%360 );
	for( i=0; i<6; i++ ){
		init_rad = TestMoveMake( next_rad, init_rad );
		OS_Printf( " %d(%d) ->", init_rad, init_rad%360 );
	}
	OS_Printf( "\n" );

	// 3
	init_rad = TEST_INIT_RAD * 1.2 + 6 * PAI / 5;
	next_rad = TEST_NEXT_RAD * 1.2 + 6 * PAI / 5;
	OS_Printf( "03: %d(%d) ->", init_rad, init_rad%360 );
	for( i=0; i<6; i++ ){
		init_rad = TestMoveMake( next_rad, init_rad );
		OS_Printf( " %d(%d) ->", init_rad, init_rad%360 );
	}
	OS_Printf( "\n" );
	OS_Printf( "\n" );




	// 0
	init_rad = TEST_INIT_RAD;
	next_rad = TEST_NEXT_RAD;
	OS_Printf( "10: %d(%d) ->", init_rad, init_rad%360 );
	for( i=0; i<6; i++ ){
		init_rad = TestMoveMake( next_rad, init_rad );
		OS_Printf( " %d(%d) ->", init_rad, init_rad%360 );
	}
	OS_Printf( "\n" );

	// 1
	init_rad = TEST_INIT_RAD * 1.5 + 5 * PAI / 3;
	next_rad = TEST_NEXT_RAD * 1.5 + 5 * PAI / 3;
	init_rad %= 360;
	next_rad %= 360;
	OS_Printf( "11: %d(%d) ->", init_rad, init_rad%360 );
	for( i=0; i<6; i++ ){
		init_rad = TestMoveMake( next_rad, init_rad );
		OS_Printf( " %d(%d) ->", init_rad, init_rad%360 );
	}
	OS_Printf( "\n" );

	// 2
	init_rad = TEST_INIT_RAD * 0.8 + 2 * PAI / 3;
	next_rad = TEST_NEXT_RAD * 0.8 + 2 * PAI / 3;
	init_rad %= 360;
	next_rad %= 360;
	OS_Printf( "12: %d(%d) ->", init_rad, init_rad%360 );
	for( i=0; i<6; i++ ){
		init_rad = TestMoveMake( next_rad, init_rad );
		OS_Printf( " %d(%d) ->", init_rad, init_rad%360 );
	}
	OS_Printf( "\n" );

	// 3
	init_rad = TEST_INIT_RAD * 1.2 + 6 * PAI / 5;
	next_rad = TEST_NEXT_RAD * 1.2 + 6 * PAI / 5;
	init_rad %= 360;
	next_rad %= 360;
	OS_Printf( "13: %d(%d) ->", init_rad, init_rad%360 );
	for( i=0; i<6; i++ ){
		init_rad = TestMoveMake( next_rad, init_rad );
		OS_Printf( " %d(%d) ->", init_rad, init_rad%360 );
	}
	OS_Printf( "\n" );
	OS_Printf( "\n" );


	// 0
	init_rad = TEST_INIT_RAD;
	next_rad = TEST_NEXT_RAD;
	init_rad += 360;
	OS_Printf( "20: %d(%d) ->", init_rad, init_rad%360 );
	for( i=0; i<6; i++ ){
		init_rad = TestMoveMake( next_rad, init_rad );
		OS_Printf( " %d(%d) ->", init_rad, init_rad%360 );
	}
	OS_Printf( "\n" );

	// 1
	init_rad = TEST_INIT_RAD * 1.5 + 5 * PAI / 3;
	next_rad = TEST_NEXT_RAD * 1.5 + 5 * PAI / 3;
	init_rad %= 360;
	next_rad %= 360;
	init_rad += 360;
	OS_Printf( "21: %d(%d) ->", init_rad, init_rad%360 );
	for( i=0; i<6; i++ ){
		init_rad = TestMoveMake( next_rad, init_rad );
		OS_Printf( " %d(%d) ->", init_rad, init_rad%360 );
	}
	OS_Printf( "\n" );

	// 2
	init_rad = TEST_INIT_RAD * 0.8 + 2 * PAI / 3;
	next_rad = TEST_NEXT_RAD * 0.8 + 2 * PAI / 3;
	init_rad %= 360;
	next_rad %= 360;
	init_rad += 360;
	OS_Printf( "22: %d(%d) ->", init_rad, init_rad%360 );
	for( i=0; i<6; i++ ){
		init_rad = TestMoveMake( next_rad, init_rad );
		OS_Printf( " %d(%d) ->", init_rad, init_rad%360 );
	}
	OS_Printf( "\n" );

	// 3
	init_rad = TEST_INIT_RAD * 1.2 + 6 * PAI / 5;
	next_rad = TEST_NEXT_RAD * 1.2 + 6 * PAI / 5;
	init_rad %= 360;
	next_rad %= 360;
	init_rad += 360;
	OS_Printf( "23: %d(%d) ->", init_rad, init_rad%360 );
	for( i=0; i<6; i++ ){
		init_rad = TestMoveMake( next_rad, init_rad );
		OS_Printf( " %d(%d) ->", init_rad, init_rad%360 );
	}
	OS_Printf( "\n" );
	OS_Printf( "\n" );
}
#endif